package com.cleanly.boot.dao.impl;

import com.cleanly.boot.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;

/**
 * @author wangyupeng
 * @despriction:
 * @ate:Created in 9:01 2019/1/15
 * @modify By:
 */
@Slf4j
public class UserProvider {

    public String getInfo(@Param("user") User user){
        StringBuilder sql = new StringBuilder("select * from t_user where 1=1");
        if (!"".equals(user.getUserId())){
            sql.append(" and user_id =#{user.userId}");
         }
        log.info("查询sql：{}",sql.toString());
        return sql.toString();
    }

    public String addUser(@Param("user") User user){
        String sql = "insert into t_user values('"+user.getUserId()+"','"+user.getUsername()+"','"+user.getPassword()+"','"+user.getPhoneNum()+"')";

        log.info("插入sql：{}",sql);
        return sql;
    }

    public String  deleteUser(@Param("user") User user){
        String sql ="delete from t_user where user_id ="+user.getUserId()+"";
        log.info("删除的sql：{}",sql);

        return sql;
    }

    public String  updateUser(@Param("user") User user){
        String sql ="update t_user set  username = '"+user.getUsername()+"',password ='"+user.getPassword()+"',phone_num='"+user.getPhoneNum()+"'  where user_id ="+user.getUserId()+"";
        log.info("修改的sql：{}",sql);
        return sql;
    }

    public String login(@Param("user") User user){
        String sql = "select 1 from t_user where username = '"+user.getUsername()+"' and password = '"+user.getPassword()+"' ";
        log.info("查询的sql：{}",sql);
        return sql;
    }
}
